/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.niedziela12.pai.ejb.dto;

import com.niedziela12.pai.ejb.entities.Hotel;
import com.niedziela12.pai.ejb.entities.Room;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Kamil
 */
public class HotelDTO implements Serializable {
    
    private static final long serialVersionUID = 1L;
    private Long id;
    private List<RoomDTO> rooms;
    private String name;
    private String city;
    private String street;
    private String description;

    public HotelDTO(){   
        rooms = new ArrayList<RoomDTO>();
    }
    
    public HotelDTO(Hotel hotel) {
        if (hotel != null) {
            this.id = hotel.getId();
            this.rooms = new ArrayList<RoomDTO>();
//            for (Room r : hotel.getRooms()) {
//                rooms.add(new RoomDTO(r));
//            }
            this.name = hotel.getName();
            this.city = hotel.getCity();
            this.street = hotel.getStreet();
            this.description = hotel.getDescription();
        }
    }
    
    public Hotel toHotel(){
        Hotel hotel = new Hotel();
        hotel.setId(id);
        hotel.setCity(city);
        hotel.setDescription(description);
        hotel.setName(name);
        hotel.setStreet(street);
        List<Room> rms = new ArrayList<Room>();
        for(RoomDTO r : rooms)rms.add(r.toRoom());
        hotel.setRooms(rms);
        return hotel;
    }
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public List<RoomDTO> getRooms() {
        return rooms;
    }

    public void setRooms(List<RoomDTO> rooms) {
        this.rooms = rooms;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final HotelDTO other = (HotelDTO) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Hotel '"+ name + "'";
    }
 
}
